package com.uff.hmstpa.model.impl;

import java.util.ArrayList;
import java.util.List;

import com.uff.hmstpa.model.ScheduleSystemModel;
import com.uff.hmstpa.model.domain.Appointment;
import com.uff.hmstpa.model.domain.Doctor;
import com.uff.hmstpa.model.domain.Healthplan;
import com.uff.hmstpa.model.domain.Patient;
import com.uff.hmstpa.model.mediator.ModelMediator;
import com.uff.hmstpa.util.observer.Observer;
import com.uff.hmstpa.util.observer.Subject;

public class ScheduleSystemModelImpl implements ScheduleSystemModel, Subject {

    private List<Doctor> doctors = new ArrayList<Doctor>();
    private List<Patient> patients = new ArrayList<Patient>();
    private List<Appointment> appointments = new ArrayList<Appointment>();
    private List<Healthplan> healthplans = new ArrayList<Healthplan>();
    private Doctor selectedDoctor = null;
    ModelMediator mediator = null;
    private List<Observer> observers = new ArrayList<Observer>();
    
    public void addDoctor(Doctor doctor) {
        this.doctors.add(doctor);
    }

    public void setSelectedDoctor(Doctor selectedDoctor) {
    	this.selectedDoctor = selectedDoctor;
    }

    public Doctor getSelectedDoctor() {
        return selectedDoctor;
    }
    
    public List<Doctor> getDoctors() {
    	return doctors;
    }
    
    public void addPatient(Patient p) {
    	this.patients.add(p);
    }
    
    public List<Patient> getPatients() {
    	return patients;
    }
    
    public List<Healthplan> getHealthplans() {
    	return this.healthplans;
    }
    
    public void addAppointment(Appointment appointment) {
    	this.appointments.add(appointment);    	
    }
    
	public List<Appointment> getAppointments() {
		return appointments;
	}
	
	public void setAppointments(List<Appointment> appointments) {
		this.appointments = appointments;		
	}
	
	public void addHealthplan(Healthplan healthplan) {
		this.healthplans.add(healthplan);		
	}

    public void registerObserver(Observer o) {
        this.observers.add(o);
    }

    public void removeObserver(Observer o) {
        int index = observers.indexOf(o);
        if (index >= 0) {
            observers.remove(index);
        }
    }

	public void notifyObservers(Object arg) {
		for (Observer observer : observers) {
            observer.update(this, arg);
        }		
	}

	public void setMediator(ModelMediator mediator) {
		this.mediator = mediator;		
	}
	
	public ModelMediator getMediator() {
		return this.mediator;
	}

}
